package cn.edu.ujn.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.edu.ujn.dao.BaseDict;
import cn.edu.ujn.dao.Customer;
import cn.edu.ujn.service.IBaseDictService;



@Controller
public class BaseDictController {
	@Autowired
	private IBaseDictService baseDictService;

	@Autowired
	private BaseDict baseDict;
	
	@RequestMapping(value = "/select2")
	public String selectBaseDict(BaseDict baseDict,Model model) {
		baseDict  = baseDictService.selectBaseDict(baseDict.getDictId());
		model.addAttribute("bas",baseDict);
		return "basedict";
	}
	
	@RequestMapping(value = "/insert2")
	public String addBaseDict(BaseDict baseDict) {
		int add  = baseDictService.addBaseDict(baseDict);
		return "basedictadd";
	}
	
	

	@RequestMapping(value = "/basezengjia")
	public String ZengJia() {
		return "basedictinsert";
	}


	@RequestMapping(value ="/baseDict/find")
	 public String findBaseDictByType(String dictId, String dictTypeName,String dictItemName,Integer dictSort,String dictEnable,String dictMemo,Model model) {
		model.addAttribute("dictId", dictId);
		model.addAttribute("dictTypeName", dictTypeName);
		model.addAttribute("custAddress", dictItemName);
		model.addAttribute("dictSort", dictSort);
		model.addAttribute("dictEnable", dictEnable);
		 List<BaseDict> findBaseDictByType = baseDictService.findBaseDictByType(dictId,dictTypeName, dictItemName, dictSort, dictEnable, dictMemo);
		 model.addAttribute("findBaseDictByType",findBaseDictByType);
		 return "basedict";

	 }
	
	
	@RequestMapping(value = "/baseDict/delete")
	 @ResponseBody
	 public String deleteBaseDict(String dictId) {
		System.out.println(dictId);
		 int deleteBaseDict = baseDictService.deleteBaseDict(dictId);
		 if(deleteBaseDict > 0){			
		        return "OK";
		    }else{
		        return "FAIL";			
		    }
	 }

	@RequestMapping(value ="/baseDict/update2")
	 public String updateBaseDict2(String dictItemName,String dictId,String dictTypeCode,String dictTypeName,String dictItemCode,Integer dictSort,String dictEnable,String dictMemo) {
		baseDict.setDictItemName(dictItemName);
		baseDict.setDictEnable(dictEnable);
		baseDict.setDictId(dictId);
		baseDict.setDictItemCode(dictItemCode);
		baseDict.setDictMemo(dictMemo);
		baseDict.setDictSort(dictSort);
		baseDict.setDictTypeCode(dictTypeCode);
		baseDict.setDictTypeName(dictTypeName);
		 int updateBaseDict = baseDictService.addBaseDict(baseDict);
		 System.out.println(baseDict);
		 return "basedict";
	 }
	
	@RequestMapping(value ="/baseDict/update")
	 public String updateBaseDict( String dictId,Model model) {
		BaseDict baseDict = baseDictService.selectBaseDict(dictId);
		 model.addAttribute("base",baseDict);
		 return "basedictinsert";
	 }
	@RequestMapping(value ="/shujuzidian")
	 public String ShujuziDian() {
		 return "basedict";
	 }
	
	
	
	
}
